<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="运动员" prop="sportsmanName">
        <el-input
          v-model="queryParams.sportsmanName"
          placeholder="请输入运动员"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开始时间" prop="startTime">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.startTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="endTime">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.endTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['training:sportsmanBodyFunction:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['training:sportsmanBodyFunction:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['training:sportsmanBodyFunction:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['training:sportsmanBodyFunction:export']"
        >导出</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="sportsmanBodyFunctionList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="运动员" align="center" prop="sportsmanName" />

<!--      <el-table-column label="体重" align="center" prop="weight" />-->
      <el-table-column label="体重" align="center" :formatter="weightFormatto" />
<!--      <el-table-column label="血红蛋白" align="center" prop="hb" />-->
      <el-table-column label="血红蛋白" align="center" :formatter="stateFormat" />
<!--      <el-table-column label="血尿素氨" align="center" prop="bu" />-->
      <el-table-column label="血尿素氨" align="center" :formatter="buFormatto"  />
<!--      <el-table-column label="肌酸激酶" align="center" prop="ck" />-->
      <el-table-column label="肌酸激酶" align="center" :formatter="ckFormatto"  />
<!--      <el-table-column label="血压" align="center">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{scope.row.lbp}}~{{scope.row.hbp}}</span>lbpandhbpFormatto  -->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="血压" align="center"  :formatter="lbpandhbpFormatto" >
        <!--<template slot-scope="scope">
          <span>{{scope.row.lbp}}~{{scope.row.hbp}}</span>
        </template>-->
      </el-table-column>
<!--      <el-table-column label="尿酸" align="center" prop="ua" />-->
      <el-table-column label="尿酸" align="center" :formatter="uaFormatto"  />
<!--      <el-table-column label="晨脉" align="center" prop="hr" />-->
      <el-table-column label="晨脉" align="center" :formatter="hrFormatto"   />
<!--      <el-table-column label="血清睾酮" align="center" prop="st" />-->
      <el-table-column label="血清睾酮" align="center" :formatter="stFormatto"    />
<!--      <el-table-column label="血乳酸" align="center" prop="bla" />-->
      <el-table-column label="血乳酸" align="center" :formatter="blaFormatto" />
<!--  stFormatto blaFormatto   -->
      <!--<el-table-column label="开始时间" align="center" prop="startTime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结束时间" align="center" prop="endTime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>-->
      <el-table-column label="创建时间" align="center" prop="ctime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.ctime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['training:sportsmanBodyFunction:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改sportsmanBodyFunction对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="运动员" prop="sportsmanId">
          <el-select
                  v-model="form.sportsmanId"
                  placeholder="请选择运动员"
                  clearable
                  size="small"
                  style="width: 240px"
          >
            <el-option
                    v-for="dict in sportsmanNameList"
                    :key="dict.id"
                    :label="dict.name"
                    :value="dict.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="体重" prop="weight">
          <el-input v-model="form.weight" placeholder="请输入体重" />
        </el-form-item>
        <el-form-item label="血红蛋白" prop="hb">
          <el-input v-model="form.hb" placeholder="请输入血红蛋白" />
        </el-form-item>
        <el-form-item label="血尿素氨" prop="bu">
          <el-input v-model="form.bu" placeholder="请输入血尿素氨" />
        </el-form-item>
        <el-form-item label="肌酸激酶" prop="ck">
          <el-input v-model="form.ck" placeholder="请输入肌酸激酶" />
        </el-form-item>
        <el-form-item label="高压" prop="hbp">
          <el-input v-model="form.hbp" placeholder="请输入高压" />
        </el-form-item>
        <el-form-item label="低压" prop="lbp">
          <el-input v-model="form.lbp" placeholder="请输入低压" />
        </el-form-item>
        <el-form-item label="尿酸" prop="ua">
          <el-input v-model="form.ua" placeholder="请输入尿酸" />
        </el-form-item>
        <el-form-item label="晨脉" prop="hr">
          <el-input v-model="form.hr" placeholder="请输入晨脉" />
        </el-form-item>
        <el-form-item label="血清睾酮" prop="st">
          <el-input v-model="form.st" placeholder="请输入血清睾酮" />
        </el-form-item>
        <el-form-item label="血乳酸" prop="bla">
          <el-input v-model="form.bla" placeholder="请输入血乳酸" />
        </el-form-item>
        <el-form-item label="采集时间" prop="startTime">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.startTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择采集时间">
          </el-date-picker>
        </el-form-item>
        <!--<el-form-item label="结束时间" prop="endTime">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.endTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择结束时间">
          </el-date-picker>
        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSportsmanBodyFunction, getSportsmanBodyFunction, delSportsmanBodyFunction, addSportsmanBodyFunction, updateSportsmanBodyFunction, exportSportsmanBodyFunction } from "@/api/training/sportsmanBodyFunction";
import {listSportsmanName} from "@/api/training/leaveForm";
export default {
  name: "SportsmanBodyFunction",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // sportsmanBodyFunction表格数据
      sportsmanBodyFunctionList: [],
      sportsmanNameList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sportsmanName: undefined,
        weight: undefined,
        hb: undefined,
        bu: undefined,
        ck: undefined,
        hbp: undefined,
        lbp: undefined,
        ua: undefined,
        hr: undefined,
        st: undefined,
        bla: undefined,
        startTime: undefined,
        endTime: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        sportsmanId: [
          { required: true, message: "运动员Id不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getNameList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      listSportsmanBodyFunction(this.queryParams).then(response => {
        this.sportsmanBodyFunctionList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        sportsmanId: undefined,
        weight: undefined,
        hb: undefined,
        bu: undefined,
        ck: undefined,
        bp: undefined,
        ua: undefined,
        hr: undefined,
        st: undefined,
        bla: undefined,
        startTime: undefined,
        endTime: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加";
      this.getNameList();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getSportsmanBodyFunction(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改";
        this.getNameList();
      });
    },
    getNameList() {
      this.loading = true;
      listSportsmanName(this.queryParams).then(response => {
        this.sportsmanNameList = response.rows;
        this.total = response.total;
        this.loading = false;
      });

    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateSportsmanBodyFunction(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          } else {
            addSportsmanBodyFunction(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delSportsmanBodyFunction(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportSportsmanBodyFunction(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    },
    stateFormat(row) {
      if (row.hb === 0 ) {
        return '-'
      } else  {
        return row.hb
      }
    },
    // weightFormatto
    weightFormatto(row) {
      if (row.weight === 0 ) {
        return '-'
      } else  {
        return row.weight
      }
    },
  //buFormatto
    buFormatto(row) {
      if (row.bu === 0 ) {
        return '-'
      } else  {
        return row.bu
      }
    },
    //ckFormatto
    ckFormatto(row) {
      if (row.ck === 0 ) {
        return '-'
      } else  {
        return row.ck
      }
    },
// uaFormatto
    uaFormatto(row) {
      if (row.ua === 0 ) {
        return '-'
      } else  {
        return row.ua
      }
    },
// hrFormatto
    hrFormatto(row) {
      if (row.hr === 0 ) {
        return '-'
      } else  {
        return row.hr
      }
    },
  //  <!--  stFormatto blaFormatto   -->
    stFormatto(row) {
      if (row.st === 0 ) {
        return '-'
      } else  {
        return row.st
      }
    },
    blaFormatto(row) {
      if (row.bla === 0 ) {
        return '-'
      } else  {
        return row.bla
      }
    },
 //     <span>{{scope.row.lbp}}~{{scope.row.hbp}}</span>lbpandhbpFormatto
    lbpandhbpFormatto(row) {
      if (row.lbp === 0 ) {
        return '-'
//         return '' +row.lbp + '~'+ row.hbp +'';

      } else  {
        return '' +row.lbp + ' ~  '+ row.hbp +'';
      }
    },



  }
};
</script>